﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CURE.Common
{
    public static class StringTool
    {
        /// <summary>
        /// 数据库数字转换成对应需要显示的字符串
        /// </summary>
        /// <param name="columnname"></param>
        /// <param name="num"></param>
        /// <returns></returns>
        public static string NumChangeToStr(string columnname, string num)
        {
            string str = "";
            switch (columnname)
            {
                case "FLAG":
                    switch (num)
                    {
                        case "0": str = "未启用"; break;
                        case "1": str = "已启用"; break;
                        default: str = "未知"; break;
                    };
                    break;
                case "STATE":
                    switch (num)
                    {
                        case "0": str = "未使用"; break;
                        case "1": str = "已使用"; break;
                        case "-1": str = "已停用"; break;
                        default: str = "未知"; break;
                    }
                    break;
                case "FULL":
                    switch (num)
                    {
                        case "0": str = "未存储"; break;
                        case "1": str = "已存储"; break;
                        case "2": str = "已满"; break;
                        default: str = "未知"; break;
                    }
                    break;
                case "STORAGESTATE":
                    switch (num)
                    {
                        case "0": str = "未完成"; break;
                        case "1": str = "已完成"; break;
                        default: str = "未知"; break;
                    }
                    break;
                case "STORAGEMASTERSTATE":
                    switch (num)
                    {
                        case "0": str = "出库"; break;
                        case "1": str = "在库"; break;
                        default: str = "未知"; break;
                    }
                    break;
                case "MACHINE":
                    switch (num)
                    {
                        case "0": str = "关闭"; break;
                        case "1": str = "开启"; break;
                        default: str = "未知"; break;
                    }
                    break;
                default: break;
            }
            return str;
        }

        /// <summary>
        /// 班次转化
        /// </summary>
        /// <param name="shift"></param>
        /// <returns></returns>
        public static string ShiftSplit(string shift)
        {
            if (string.IsNullOrEmpty(shift) || shift == "")
            {
                return "未知";
            }
            else
            {
                shift = shift.Substring(shift.Length - 1, 1);
                if (shift == "1")
                {
                    return "早班";
                }
                else if (shift == "2")
                {
                    return "中班";
                }
                else
                {
                    return "晚班";
                }
            }
        }

        /// <summary>
        /// 生胎日限结果转换
        /// </summary>
        /// <param name="limit_result"></param>
        /// <returns></returns>
        public static string LimitResultChange(string limit_result)
        {
            if (limit_result == "0")
            {
                return "超限";
            }
            else if (limit_result == "1")
            {
                return "未超限";
            }
            else if (limit_result == "2")
            {
                return "未找到日限";
            }
            else
            {
                return "未知";
            }
        }

        /// <summary>
        /// 规格同步形式
        /// </summary>
        /// <param name="hm"></param>
        /// <returns></returns>
        public static string HM(string hm)
        {
            if (hm == "0")
            {
                return "自动";
            }
            else
            {
                return "手动";
            }
        }

        /// <summary>
        /// 不良类别转换文字
        /// </summary>
        /// <param name="cate"></param>
        /// <returns></returns>
        public static string BLCate(string cate)
        {
            
            switch (cate)
            {
                case "A": return cate + "(橡胶焦化)";
                case "B": return cate + "(下BB滞留)";
                case "C": return cate + "(手动炼制)";
                case "D": return cate + "(未炼开)";
                case "E": return cate + "(计量异常)";
                case "F": return cate + "(温度异常)";
                case "G": return cate + "(异物混入)";
                case "H": return cate + "(过期品)";
                case "I": return cate + "(无F卡)";
                case "J": return cate + "(橡胶有水)";
                case "K": return cate + "(药品异常)";
                case "L": return cate + "(其他)";
                default: return "";
            }
        }

        /// <summary>
        /// 实验状态转换
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        public static string ExpCharge(string state)
        {
            switch (state)
            {
                case "0": return "实验中"; 
                case "1": return "实验完成,等待审核";
                case "2": return "通过审核"; 
                case "-1": return "审核未通过"; 
                default: return "未填写实验申请"; 
            }
        }

        /// <summary>
        /// 审核状态转换
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        public static string ApprovalCharge(string state)
        {
            switch (state)
            {
                case "0": return "通过审核";
                case "1": return "未通过审核";
                default: return "未审核";
            }
        }

        /// <summary>
        /// 获取文件名
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static string GetFileName(string path)
        {
            int inde = path.LastIndexOf("/");
            return path.Substring(inde + 1, path.Length - inde - 1);
        }

        
    }
}